package com.app.task;

import com.app.common.Constants;
import org.springframework.scheduling.annotation.Scheduled;

import java.util.Date;
import java.util.Queue;

// Component
public class Scheduler {

    @Scheduled(fixedRate = 2000)
    public void testTasksSet() {
        Listen.setData(Constants.QUEUELIST);
    }

    @Scheduled(fixedRate = 1000)
    public void testTasksGet() {
        Listen.getData(Constants.QUEUELIST);
    }

}

class Listen {
    public static void setData(Queue<String> list) {
        list.offer(String.valueOf(new Date().getTime()));
    }

    public static void getData(Queue<String> list) {
        System.out.println(" ");

        if (list.size() == 5) {
            System.out.println("取出的第一条：" + list.poll());
        }

        int i = 0;
        for (String s : list) {
            System.out.println("数据: " + i++ + " # " + s);
        }

    }
}
